// pages/CarWashList/CarWashList.js
var that,
  api = new (require('../../utils/api.js')),
  headimg = api.getimgurl(),
  app = getApp(),
  util = new (require('../../utils/util.js'));
Page({

  /**
   * 页面的初始数据
   */
  data: {
    page:1,
    nextPage:0,
    list:[],
    isload:!1,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    that=this;
    that.getdata()
  },
  getdata(){
    wx.showLoading({
      title: '加载中',
    })
    let {page,list}=that.data
    api.washrecord(page,res=>{
      wx.hideLoading()
      that.setData({isload:!0})
      if(res.data.code==0){
        let {orderArr,nextPage}=res.data.entity.data
        orderArr.forEach(x=>{
          x['newpayTime'] = util.toDate1(x.payTime)
          x['newvalidTime'] = util.toDate1(x.validTime)
          x.finishdate = x.finishTime==0?x.finishTime:util.toDate1(x.finishTime)
          list.push(x)
        })
        that.setData({list,nextPage})
      }
    })
  },
  to(e){
    let {orderid}=e.currentTarget.dataset
    wx.navigateTo({
      url: '../evaluate/evaluate?orderid='+orderid,
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let {isload}=that.data
    if(isload){
      that.setData({list:[],page:1},()=>{
        that.getdata()
      })
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    wx.stopPullDownRefresh();
    that.setData({list:[],page:1},()=>{
      that.getdata();
    })
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    let {page,nextPage}=that.data
    if(nextPage==1){
      page=page+1
      that.setData({page},()=>{
        that.getdata()
      })
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})